package com.example.controller;

import com.example.entity.Noregister;
import com.example.entity.User;
import com.example.mapper.PassMapper;
import com.example.mapper.UserMapper;
import com.example.service.NoregisterService;
import com.example.service.PassService;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/manager")
public class managerController {
    @Autowired
    UserService userService;
    @Autowired
    UserMapper userMapper;
    @Autowired
    NoregisterService noregisterService;
    @Autowired
    PassMapper passMapper;
    @Autowired
    PassService passService;
    @PostMapping("/list")
    public List<User> list(){
        return this.userService.list();
    }

    @PostMapping("/noregister")
    public List<Noregister> noregisterList(){
        return this.noregisterService.list();
    }


    @PostMapping("/deleteUser")
    public String delete(HttpServletRequest request){
        String  id=request.getParameter("id");
        int id2=Integer.valueOf(id);
        passMapper.deleteByid(id2);
        return "删除成功";
    }

    @PostMapping("/edit")
    public String edit(HttpServletRequest request){
        String temper=request.getParameter("temper");
        String health=request.getParameter("health");
        String statue2=request.getParameter("statue");
        String name=request.getParameter("name");
        String academic=request.getParameter("academic");
        this.userMapper.edit(temper,health,statue2,name,academic);
        return "ok";
    }

    @PostMapping("/addUser")
    public String add(HttpServletRequest request){
        String name=request.getParameter("name");
        String academic=request.getParameter("academic");
        String temper=request.getParameter("temper");
        String health=request.getParameter("health");
        String statue=request.getParameter("statue");
        this.userMapper.add(name,academic,temper,health,statue);
        return "添加成功";
    }

}
